package com.weng.cloud.service8881.concurrenct.algorithm.recursion.base;

import lombok.Getter;

import java.util.LinkedList;
import java.util.List;

/**
 * @Author: weng
 * @Date: 2022/7/9
 * @Description: com.weng.cloud.service8881.concurrenct.algorithm.recursion
 */
public class Node<P, M> {
    @Getter
    private final P position;
    private final M move;
    private final Node<P, M> prev;

    public Node(P position, M move, Node<P, M> prev) {
        this.position = position;
        this.move = move;
        this.prev = prev;
    }

    public List<M> asMoveList() {
        List<M> solution = new LinkedList<>();
        for (Node<P, M> node = this; node.move != null; node = node.prev) {
            solution.add(0, node.move);
        }
        return solution;
    }
}
